/**
 * Created by Jack Xue on 20101024
 */
package org.code.jack.jweberp.service.impl;

import java.io.Serializable;
import java.util.List;

import org.code.jack.jweberp.dao.IGenericDao;
import org.code.jack.jweberp.service.ICrudService;
import org.code.jack.jweberp.utils.GenericsUtils;

public abstract class CrudServiceBean<T, E extends IGenericDao<T>> implements ICrudService<T> {

	@SuppressWarnings("unchecked")
	public Class<T> clz = GenericsUtils.getSuperClassGenericType(this.getClass());
	public E genericDao;
	
	@Override
	public T createEntity(T obj) {
		genericDao.persistEntity(obj);
		return obj;
	}

	public E getGenericDao() {
		return genericDao;
	}

	public void setGenericDao(E genericDao) {
		this.genericDao = genericDao;
	}

	@Override
	public T getEntity(Serializable id) {
		return genericDao.getEntity(id);
	}

	@Override
	public boolean updateEntity(T obj) {
		return genericDao.mergeEntity(obj);
		
	}

	@Override
	public boolean deleteEntity(Serializable id) {
		return genericDao.removeEntity(id);
	}

	@Override
	public List<T> getEntityList() {
		List<T> entityList = this.genericDao.findByJPQL();
		return entityList;
	}
}
